package com.sugon.controller.tool;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.ToolsScrapEntity;
import com.sugon.modules.tools.service.IToolsManager;
import com.sugon.service.ToolsScrapService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 工装报废Controller
 *
 * @author sugon
 * @date 2019-08-05 19:28:35
 */
@Controller
@RequestMapping("toolsscrap")
public class ToolsScrapController {

    @Autowired
    private ToolsScrapService toolsScrapService;
    @Autowired
    private IToolsManager toolsManager;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("toolsscrap:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<ToolsScrapEntity> toolsScrapList = toolsScrapService.queryList(query);
        int total = toolsScrapService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(toolsScrapList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("toolsscrap:info")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        ToolsScrapEntity toolsScrap = toolsScrapService.queryObject(id);

        return R.ok().put("toolsScrap", toolsScrap);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("toolsscrap:save")
    @ResponseBody
    public R save(@RequestBody ToolsScrapEntity toolsScrap) {
        return toolsManager.addToolsScrapRecord(toolsScrap) ? R.ok() : R.error();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("toolsscrap:update")
    @ResponseBody
    public R update(@RequestBody ToolsScrapEntity toolsScrap) {
        toolsScrapService.update(toolsScrap);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/check")
    @RequiresPermissions("toolsscrap:check")
    @ResponseBody
    public R check(@RequestBody ToolsScrapEntity toolsScrap) {
        toolsScrapService.check(toolsScrap);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/peCheck")
    @RequiresPermissions("toolsscrap:peCheck")
    @ResponseBody
    public R peCheck(@RequestBody ToolsScrapEntity toolsScrap) {
        toolsScrapService.peCheck(toolsScrap);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("toolsscrap:delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        toolsScrapService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<ToolsScrapEntity> list = toolsScrapService.queryList(params);

        return R.ok().put("list", list);
    }
}
